import Mock from 'mockjs';

// 生成列表数据
Mock.mock('/api/v1/industry-report/list/', 'get', (options: { url: string }) => {
  const params = new URLSearchParams(options.url.split('?')[1]);
  const page = parseInt(params.get('page') || '1');
  const pageSize = parseInt(params.get('pageSize') || '20');

  return {
    code: 200,
    data: {
      total: 100,
      list: Array(pageSize).fill(null).map(() => ({
        reportId: Mock.Random.guid(),
        title: Mock.Random.ctitle(5, 20),
        industry: Mock.Random.pick(['新能源', '芯片', '人工智能', '生物医药']),
        publishTime: Mock.Random.datetime(),
        status: Mock.Random.pick(['draft', 'published']),
        author: Mock.Random.cname(),
        summary: Mock.Random.cparagraph(1, 2),
        tags: Mock.Random.shuffle(['技术创新', '市场分析', '发展趋势', '政策解读'], 3),
        viewCount: Mock.Random.integer(100, 10000)
      }))
    },
    message: 'success'
  };
});

// 获取详情
Mock.mock(/\/api\/v1\/industry-report\/[\w-]+$/, 'get', () => {
  return {
    code: 200,
    data: {
      reportId: Mock.Random.guid(),
      title: Mock.Random.ctitle(5, 20),
      industry: Mock.Random.pick(['新能源', '芯片', '人工智能', '生物医药']),
      publishTime: Mock.Random.datetime(),
      status: Mock.Random.pick(['draft', 'published']),
      author: Mock.Random.cname(),
      content: Mock.Random.cparagraph(10, 20),
      summary: Mock.Random.cparagraph(1, 2),
      tags: Mock.Random.shuffle(['技术创新', '市场分析', '发展趋势', '政策解读'], 3),
      attachments: Array(2).fill(null).map(() => ({
        fileId: Mock.Random.guid(),
        fileName: Mock.Random.word(5, 10) + '.pdf',
        fileSize: Mock.Random.integer(1000, 10000000),
        fileType: 'pdf'
      })),
      references: Array(3).fill(null).map(() => ({
        title: Mock.Random.ctitle(5, 15),
        url: Mock.Random.url(),
        type: Mock.Random.pick(['paper', 'news', 'report'])
      })),
      viewCount: Mock.Random.integer(100, 10000),
      updateTime: Mock.Random.datetime()
    },
    message: 'success'
  };
});

// 创建报告
Mock.mock('/api/v1/industry-report', 'post', () => {
  return {
    code: 200,
    data: {
      reportId: Mock.Random.guid()
    },
    message: '创建成功'
  };
});

// 更新报告
Mock.mock(/\/api\/v1\/industry-report\/[\w-]+$/, 'put', () => {
  return {
    code: 200,
    message: '更新成功'
  };
});

// 删除报告
Mock.mock(/\/api\/v1\/industry-report\/[\w-]+$/, 'delete', () => {
  return {
    code: 200,
    message: '删除成功'
  };
});